package com.gcxy.controller;


import com.gcxy.dto.Pen.InsertDto;
import com.gcxy.dto.Pen.UpdateDto;
import com.gcxy.service.PenService;
import com.gcxy.utils.R;
import com.gcxy.vo.Pen.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.convert.PeriodUnit;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wlp
 * @since 2023-12-19
 */
@RestController
@RequestMapping("/pen")
@Api(tags = "圈舍管理")
public class PenController {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private PenService penService;
    @ApiOperation("圈舍新增")
    @PostMapping("addpen")
    public R addPen(@Valid @RequestBody InsertDto requestBody){
        logger.info("正在新增圈舍");
        R result=penService.addPen(requestBody);
        return result;
    }
    @ApiOperation("圈舍分页查询")
    @PostMapping("page")
    public R pagePen(@RequestBody PageVo requestBody){
        logger.info("正在圈舍分页");
        R result=penService.pagePen(requestBody);
        return result;
    }
    @ApiOperation("圈舍修改")
    @PutMapping("update")
    public R penUpdate(@Valid @RequestBody UpdateDto requestBody){
        logger.info("正在修改圈舍");
        R result=penService.penUpdate(requestBody);
        return result;
    }
    @ApiOperation("修改圈舍状态")
    @PutMapping("updateState/{penId}/{penState}")
    public R penUpdateState(@PathVariable Integer penId,@PathVariable Integer penState){
        logger.info("正在修改圈舍状态");
        R result=penService.penUpdateState(penId,penState);
        return result;
    }
    @ApiOperation("按照牧场获取圈舍")
    @GetMapping("getPenByRanchId/{ranchId}")
    public R getPenByRanchId(@PathVariable Integer ranchId){
        logger.info("正在按照ranchid获取圈舍");
        R result =penService.getPenByRanchId(ranchId);
        return result;
    }
}

